<?php

namespace App\Listeners;

use App\Constant\QueueKey;
use App\Events\UserLoanRequestQueryResultEvent;
use App\Facades\MoneyPlatformRequestFacade;
use App\Models\UserLoanRequest;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class UserLoanRequestQueryResultEventListener implements ShouldQueue
{
    use InteractsWithQueue;

    public $queue = QueueKey::QUEUE_LOAN_REQUEST_QUERY_RESULT;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Description:事件处理方法
     * Author: Sam
     * DateTime: 2019/1/15 18:31
     * @param UserLoanRequestQueryResultEvent $event
     * @throws \App\Exceptions\GeneralException
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \MathPHP\Exception\BadParameterException
     */
    public function handle(UserLoanRequestQueryResultEvent $event)
    {
        $loan = UserLoanRequest::where(['credit_id' => $event->credit_id, 'current' => UserLoanRequest::CURRENT_NOW, 'status' => UserLoanRequest::STATUS_APPLY])
            ->where('retry','<>',UserLoanRequest::RETRY_YES)
            ->first();
        if ($loan) {
            UserLoanRequest::getResult($loan);
        }
    }
}
